package org.itzixi.service;

import jakarta.annotation.Resource;
import org.itzixi.api.feign.FileFein;
import org.itzixi.grace.result.GraceJSONResult;
import org.itzixi.mapper.UsersMapper;
import org.itzixi.pojo.Users;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 用户表 服务实现类
 * </p>
 *
 * @author 顾文龙
 * @since 2024-06-12
 */
@Service
public class UsersService{

    @Resource
    private UsersMapper usersMapper;

    @Resource
    private FileFein fileFein;


    public Users createUsers(String mobile, String nickname) {

        Users users = usersMapper.addUser(mobile, nickname);
        String qrCodeUrl = getQrCodeUrl(users.getWechatNum(), "temp");
        users.setWechatNumImg(qrCodeUrl);
        usersMapper.insert(users);
        return users;
    }

    public Users queryMobileIfExist(String mobile) {
        return usersMapper.queryMobileIfExist(mobile);
    }

    private String getQrCodeUrl(String wechatNum, String userId){
        GraceJSONResult<String> result = fileFein.generatorQrCode(wechatNum, userId);
        String qrCodeUrl = result.getData();
        return qrCodeUrl;
    }
}
